package us.wili.dev.third.util.example.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import us.wili.dev.common.util.xinge.v2.XinGeProperties;
import us.wili.dev.common.util.xinge.v2.XinGeUtil;

/**
 * author: lefore
 * date: 2018/10/22
 */
@Configuration
@EnableConfigurationProperties({XinGeConfig.XinGeAndroidPropertiesCreator.class, XinGeConfig.XinGeIOSPropertiesCreator.class})
public class XinGeConfig {

    @Bean(name = "androidXinGeUtil")
    public XinGeUtil androidXinGeUtil(XinGeAndroidPropertiesCreator propCreator) {
        XinGeProperties prop = propCreator.getAndroid();
        return new XinGeUtil(prop);
    }

    @Bean(name = "iosXinGeUtil")
    public XinGeUtil iosXinGeUtil(XinGeIOSPropertiesCreator propCreator) {
        XinGeProperties prop = propCreator.getIos();
        return new XinGeUtil(prop);
    }

    @ConfigurationProperties(prefix = "xinge")
    public static class XinGeAndroidPropertiesCreator {

        private XinGeProperties android;

        public XinGeProperties getAndroid() {
            return android;
        }

        public void setAndroid(XinGeProperties android) {
            this.android = android;
        }
    }

    @ConfigurationProperties(prefix = "xinge")
    public static class XinGeIOSPropertiesCreator {

        private XinGeProperties ios;

        public XinGeProperties getIos() {
            return ios;
        }

        public void setIos(XinGeProperties ios) {
            this.ios = ios;
        }
    }
}